import csv
import numpy as np
import queue
from node_class import Node
class CSV_Loader:
    file_name:str
    title:list
    data:list
    def __init__(self,name):
        self.file_name=name
        with open(self.file_name,'r') as data:
            lines=csv.reader(data)
            self.title=next(lines)
            self.data=list(lines)


class Road:
    start_id:int
    end_id:int
    distance_value:float
    pass_nodes:list[int]
    def __init__(self,start_id:int,end_id:int):
        self.start_id=start_id
        self.end_id=end_id
        self.pass_nodes=[]


class Relation_Inputer:  
    '''
    节点关系输入器
    ''' 
    nodes_side_count:int
    '''
    边总数
    '''
    nodes:dict[int,Node]
    '''
    节点字典[id,Node]
    '''
    def __init__(self,node_relation_filename:str,nodes=None):
        loader=CSV_Loader(node_relation_filename).data
        if(nodes==None):
            self.nodes=dict()
        else:
            self.nodes=nodes
        self.nodes_side_count=0
        for line in loader:
            if((int)(line[0]) not in self.nodes.keys()):
                self.nodes[(int)(line[0])]=Node((int)(line[0]))              
            if((int)(line[1]) not in self.nodes.keys()):
                self.nodes[(int)(line[1])]=Node((int)(line[1]))
            node:Node=self.nodes[(int)(line[0])]
            node.neighbors[(int)(line[1])]=float(line[2])
            node:Node=self.nodes[(int)(line[1])]
            node.neighbors[(int)(line[0])]=float(line[2])
        for node in self.nodes.values():
            node:Node
            self.nodes_side_count+=len(node.neighbors)
        self.nodes_side_count/=2
class Point_Inputer:
    '''
    节点坐标输入器
    '''
    def __init__(self,node_point_filename:str,nodes:dict[int,Node]):
        loader=CSV_Loader(node_point_filename).data
        for line in loader:
            id=(int)(line[0])
            
            node:Node=nodes[id]
            node.x=float(line[1])
            node.y=float(line[2])
def Loader()-> dict[int, Node]:

    RI=Relation_Inputer("data/node_relation_1.csv")#导入节点关系数据
    node_datas=RI.nodes
    Point_Inputer("data/node_point_1.csv",node_datas)#导入节点坐标数据
    return node_datas
NODES_DATA=Loader()
        
